<%@ page language="java" contentType="text/javascript; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import='java.sql.*' %>
<%@page import="java.util.ArrayList"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>
<%@page import="net.sf.json.JSONArray"%>

<%String callback = request.getParameter("callback");%>
<%=callback %> (<%

	Connection conn = null;
	PreparedStatement pstmt = null;
	
	try{
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection(
			"jdbc:mysql://localhost/itscreater", "itscreater", "campus123");
	
		String select = "select * from Notice;";
		pstmt = conn.prepareStatement(select);
		ResultSet rs = pstmt.executeQuery();
		
		JSONObject jo = new JSONObject();
		if (rs.next()) {
			String num = rs.getString("Number");
			String title = rs.getString("Title");
			String content = rs.getString("Content");
			if (title != null) {
				title = title.replace("\n","<br>");
				title = title.replace("\u0020","&nbsp;");
			}
			if (content != null) {
				content = content.replace("\n","<br>");
				content = content.replace("\u0020","&nbsp;");
			}
			String date = rs.getString("Date");
			String time = rs.getString("Time");
			
			jo.put("Number", num);
			jo.put("Title", title);
			jo.put("Content", content);
			jo.put("Date", date);
			jo.put("Time", time);

			jo.put("success", "true");
			
		} 		
	
		out.print(jo);	
	}
	
	finally{
		try{
			pstmt.close();
		}
		catch (Exception ignored){
		}
		try{
			conn.close();
		}
		catch (Exception ignored){
		}
	}
%>);